<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>编辑预约</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            margin-bottom: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            color: #666;
        }
        input[type="text"],
        input[type="datetime-local"],
        textarea,
        select {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        textarea {
            height: 100px;
            resize: vertical;
        }
        .btn {
            display: inline-block;
            padding: 8px 15px;
            background-color: #4CAF50;
            color: white;
            text-decoration: none;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .btn:hover {
            background-color: #45a049;
        }
        .btn-cancel {
            background-color: #f44336;
            margin-left: 10px;
        }
        .btn-cancel:hover {
            background-color: #d32f2f;
        }
        .alert {
            padding: 15px;
            margin-bottom: 20px;
            border-radius: 4px;
        }
        .alert-danger {
            background-color: #f2dede;
            color: #a94442;
            border: 1px solid #ebccd1;
        }
        .info-text {
            color: #666;
            font-size: 0.9em;
            margin-top: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>编辑预约</h1>
        
        <c:if test="${not empty error}">
            <div class="alert alert-danger">${error}</div>
        </c:if>
        
        <form action="${pageContext.request.contextPath}/reservation/edit" method="post">
            <input type="hidden" name="id" value="${reservation.id}">
            <input type="hidden" name="userId" value="${reservation.userId}">
            
            <div class="form-group">
                <label for="venueId">选择场馆</label>
                <select id="venueId" name="venueId" required>
                    <c:forEach items="${venues}" var="venue">
                        <option value="${venue.id}" ${venue.id == reservation.venueId ? 'selected' : ''}>
                            ${venue.name}
                        </option>
                    </c:forEach>
                </select>
            </div>
            
            <div class="form-group">
                <label for="startTime">开始时间</label>
                <input type="datetime-local" id="startTime" name="startTime" 
                       value="<fmt:formatDate value='${reservation.startTime}' pattern='yyyy-MM-dd\'T\'HH:mm'/>" required>
            </div>
            
            <div class="form-group">
                <label for="endTime">结束时间</label>
                <input type="datetime-local" id="endTime" name="endTime" 
                       value="<fmt:formatDate value='${reservation.endTime}' pattern='yyyy-MM-dd\'T\'HH:mm'/>" required>
            </div>
            
            <div class="form-group">
                <label for="purpose">用途</label>
                <textarea id="purpose" name="purpose" required>${reservation.purpose}</textarea>
            </div>
            
            <div class="form-group">
                <label>当前状态</label>
                <div class="info-text">
                    <c:choose>
                        <c:when test="${reservation.status == 'pending'}">待审核</c:when>
                        <c:when test="${reservation.status == 'approved'}">已通过</c:when>
                        <c:when test="${reservation.status == 'rejected'}">已拒绝</c:when>
                        <c:when test="${reservation.status == 'completed'}">已完成</c:when>
                    </c:choose>
                </div>
            </div>
            
            <div class="form-group">
                <button type="submit" class="btn">保存修改</button>
                <a href="${pageContext.request.contextPath}/reservation/list" class="btn btn-cancel">取消</a>
            </div>
        </form>
    </div>
    
    <script>
        // 确保结束时间不早于开始时间
        document.getElementById('startTime').addEventListener('change', function() {
            document.getElementById('endTime').min = this.value;
        });
    </script>
</body>
</html> 